package com.zlx.mall.basic.util.collection;

import java.util.Collection;
import java.util.List;

/**
 * 集合类工具
 *
 * @author chenglong.jing
 * @date 2019/12/18 16:40
 */
public class CollectionUtil {

    public static boolean isEmpty(Collection<?> collection) {
        return (collection == null || collection.size() == 0);
    }

    public static boolean isEmpty(Object[] arr) {
        return arr == null || arr.length == 0;
    }

    public static boolean isNotEmpty(Collection<?> collection) {
        return (collection != null && collection.size() > 0);
    }

    public static boolean isNotEmpty(Object[] arr) {
        return arr != null && arr.length > 0;
    }

    public static int size(Collection<?> collection) {
        return isEmpty(collection) ? 0 : collection.size();
    }

    public static int size(Object[] arr) {
        return isEmpty(arr) ? 0 : arr.length;
    }

    public static <T> T getFirst(List<T> list) {
        return isEmpty(list) ? null : list.get(0);
    }

    public static <T> T getFirst(T[] arr) {
        return isEmpty(arr) ? null : arr[0];
    }


    private CollectionUtil() {
    }
}